<?php
namespace Account\Controller;
use Common\Controller\AdminbaseController;
class UserController extends AdminbaseController 
{   
	protected $userObj;
    protected $roleObj;
    public function _initialize()
    {
          parent::_initialize();
          $this->userObj = D("Site/User");
    }

	public function index()
	{
		$this->edit();
	}

    public function edit()
    {
        $userid=$_SESSION['ADMIN_ID'];
        $user=$this->userObj->relation(true)->find($userid);
        $this->assign("user",$user);
        $this->display("edit");    	
    }
    public function save()
    {
        $id = I('post.inputId','-1','htmlspecialchars');
        $nickname = I('post.inputName','','htmlspecialchars');
        $email = I('post.inputEmail','','htmlspecialchars');
        $password = I('post.inputPassword','','htmlspecialchars');
        $data = array();
        $data["nickname"]  = $nickname;
        $data["email"]  = $email;
        if(!empty($password)) $data["password"] = md5("lock".$password);
        $data["status"] = $status;
        if($id>0)
        {
            $editResult = $this->userObj->where("id=%d",$id)->save($data);
            $arr = array("status"=>'1',"message"=>"编辑账户信息成功","url"=>"index");
        }
        else
        {
           $arr = array("status"=>'0',"message"=>"编辑账户信息失败","url"=>"index");
        }
        echo json_encode($arr);
    }
}